﻿using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components;
using OnWork.DataCenter.Shared.Pages.DataStandard.Designer;
using System.Diagnostics.CodeAnalysis;

namespace OnWork.DataCenter.Shared.Pages.DataSource
{
    public partial class TaskConfigEditView : ComponentBase
    {
        /// <summary>
        /// 传入的配置文件
        /// </summary>
        //[CascadingParameter(Name = "BodyContext")]
        [Parameter]
        public TaskConfigVO? Config { get; set; }

        [Inject]
        [NotNull]
        protected DialogService? DialogService { get; set; }

        /// <summary>
        /// 流程配置按钮点击时
        /// </summary>
        /// <returns></returns>

        private async Task OnConfigClickAsync()
        {
            var result = await DialogService.ShowModal<StandardDesignerDialog>(new ResultDialogOption()
            {
                Title = "流程编辑",
                ButtonNoText= "取消",
                ButtonYesText= "保存",
                ComponentParameters = new Dictionary<string, object>
                {
                    [nameof(StandardDesignerDialog.ValueChanged)] = EventCallback.Factory.Create<(string,string)>(this, v =>
                    {
                        Config.DiagramData = v.Item1; //获取图JSOn值
                        Config.TaskConfigView = v.Item2; //获取配置的JSOn值
                    }),
                    [nameof(StandardDesignerDialog.OnLoadedAction)] = new Action<StandardDesigner>(x =>
                    {
                        if (!string.IsNullOrEmpty(Config.DiagramData))
                        {
                            x.LoadFormjson(Config.DiagramData); //初始化完成后加载配置
                        }
                    }),
                }
            });
        }
    }
}